package C_Paper;

import java.util.Arrays;
import java.util.Scanner;

public class C100_3 {
    // 最小富裕家庭
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int[] mon = new int[x];
        int[] tm = new int[x];
        for (int i = 0; i < x; i++) {
            mon[i] = sc.nextInt();
            tm[i] = mon[i];
        }
        for (int i = 0; i < x - 1; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            tm[a-1]+=mon[b-1];
        }
        System.out.println(Arrays.toString(mon));
        System.out.println(Arrays.toString(tm));
        int max = 0;
        for (int i = 0; i < x; i++) {
            max = Math.max(max,tm[i]);
        }
        System.out.println(max);
    }
}
